#! /bin/sh
#
# author: Enrique Martinez <enmaca@hotmail.com>
# license: GPL-3+
#
### BEGIN INIT INFO
# Provides:          clsync
# Should-Start:      $remote_fs $local_fs $syslog
# Should-Stop:       $remote_fs $local_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: clsync daemon init script
# Description:       This script launches the clsync daemon.
### END INIT INFO
#
# clsync
# chkconfig:    2345 98 02
# pidfile:     /var/run/clsync/clsync.pid

# Source function library.
. /etc/rc.d/init.d/functions

# Source networking configuration.
. /etc/sysconfig/network

CLSYNCCMD=/usr/bin/clsync

# Source monit configuration.
if [ -f /etc/sysconfig/clsync ] ; then
. /etc/sysconfig/clsync
fi

[ -f $CLSYNCCMD ] || exit 0

RETVAL=0

# See how we were called.
case "$1" in
start)
	echo -n "Starting clsync: "
	daemon $CLSYNCCMD --pid-file /var/run/clsync/clsync.pid
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && touch /var/lock/subsys/nosearch_cached
	;;
stop)
	echo -n "Stopping clsync: "
	killproc -p /var/run/clsync/clsync.pid
	RETVAL=$?
	echo
	[ $RETVAL = 0 ] && rm -f /var/lock/subsys/clsync
	;;
restart)
	$0 stop
	$0 start
	;;
reload)
	echo -n "Reloading clsync: "
	killproc -p /var/run/clsync/clsync.pid clsync -HUP
	RETVAL=$?
	echo
	;;
status)
	status -p /var/run/clsync/clsync.pid clsync
	RETVAL=$?
	;;
*)
echo "Usage: $0 (start|stop|reload|status)"
exit 1
esac

exit $RETVAL
